home *** CD-ROM | disk | FTP | other *** search
/ PC & Mediji 1998 February / PCM_9802.iso / programi / director / data.z / Behavior Library.cst / 00042_Script_Video slider < prev    next >
Text File  |  1997-05-09  |  8KB  |  257 lines

  1. -- Video Time Slider
  2.  
  3. -- Control
  4.  
  5. -- requires an 'extent' cast member 
  6. -- that limits the range the slider 'slides'
  7. -- controls the MovieTime of a video sprite,
  8. -- if the sprite is playing the slider moves automatically
  9.  
  10.  
  11.  
  12. property pDuration, pMovieTime, VideoSprite
  13.  
  14. property horizontal  -- if false, vertical
  15. property extentSprite
  16. property hiliteMember  -- looks like the handle plus hilite graphics
  17. -- also holds the member of handle while hilited
  18.  
  19. property tracking
  20. property newLocH
  21. property newLocV
  22.  
  23. property sending   -- if true, sends value when parked
  24. property dynamic   -- if true and sending true, sends value while tracking
  25. property style     -- [sendAllSprites, SendSprite, Call]
  26. property addressee -- which spritenum gets the message if SendSprite or Call
  27. property name      -- Sliders identity so messages can be traced
  28. property notify_list -- list of sprites to receive event, only has 1 item this time
  29.  
  30. property min, max  -- the range the slider maps to
  31. property valrange  -- the difference of max and min, set on begin
  32. property minScreen, maxScreen -- calculated from the screen coords of the extent
  33. property currentScreenVal -- the data point in screen coords, set in tracking
  34. property extentlength -- in screen coords, set on begin
  35.  
  36. property CurrentVal
  37.  
  38. on getPropertyDescriptionList
  39.   if the currentspritenum = 0 then 
  40.     set memdefault = 0 
  41.   else
  42.     set memref = the member of sprite the currentspritenum
  43.     set castlibnum = the castlibnum of memref
  44.     set memdefault = member (the membernum of member memref + 1) of castlib castlibnum
  45.   end if
  46.   
  47.   
  48.   set description = [:]
  49.   
  50.   addprop description, #VideoSprite, [#default: 1, #format:#integer,¼
  51.  #comment: "Video Sprite:"]
  52.   
  53.   addprop description, #extentSprite, [#default: 1, #format:#integer,¼
  54.  #comment: "Extent Sprite:"]
  55.   
  56.   addprop description, #hiliteMember, [#default: memdefault , #format:#graphic,¼
  57. #comment: "Hilite Member:"]
  58.   
  59.   addprop description, #horizontal, [#default: 1, #format:#boolean,¼
  60. #comment: "Horizontal (if not vertical):"]
  61.   
  62.   addprop description, #dynamic, [#default: 1, #format:#boolean,¼
  63. #comment: "Dynamic:"]
  64.   
  65.   return description
  66. end
  67.  
  68. on getBehaviorDescription
  69.   return "Video Control Slider"
  70. end
  71.  
  72. on compute_val me
  73.   -- relies on tracking to update the currentScreenVal (different for Hor, Vert)
  74.   set val = 0.0
  75.   set val = float(the currentScreenVal of me) / float (the extentlength of me)
  76.   set val = val * the valrange of me
  77.   set val = val + the min of me
  78.   return val
  79. end
  80.  
  81. on send_the_val me, val
  82.   -- sets the digital video time to the val * paramter {0 - movieduration}
  83.   set pMovieTime = val * pDuration
  84.   set the movieTime of sprite VideoSprite to pMovieTime 
  85.   
  86. end
  87.  
  88.  
  89. on beginSprite me
  90.   
  91.   set pDuration = the duration of sprite VideoSprite
  92.   
  93.   set the min of me = 0.0
  94.   set the max of me = 1.0
  95.   set the sending of me = true
  96.   
  97.   --
  98.   set handle = the spritenum of me
  99.   set the tracking of me = FALSE
  100.   set the newLocH of me = the locH of sprite handle
  101.   set the newLocV of me = the locV of sprite handle
  102.   
  103.   if the horizontal of me then    
  104.     set the newLocV of me = the locV of sprite the extentSprite of me
  105.     set the minScreen of me = the left of sprite the extentSprite of me
  106.     set the maxScreen of me = the right of sprite the extentSprite of me
  107.   else -- vertical slider
  108.     set the newLocH of me = the locH of sprite the extentSprite of me  
  109.     set the minScreen of me = the left of sprite the extentSprite of me
  110.     set the maxScreen of me = the right of sprite the extentSprite of me
  111.   end if
  112.   
  113.   puppetsprite handle, TRUE  -- take this out when beginSpriteAutoPuppet fixed
  114.   
  115.   set the locH of sprite handle to the newLocH of me
  116.   set the locV of sprite handle to the newLocV of me
  117.   
  118.   set the valrange of me = the max of me - the min of me
  119.   set the extentlength of me = the maxScreen of me - the minScreen of me
  120.   
  121.   if the sending of me = FALSE then  -- check for wrong input (dyn true, send false)
  122.     set the dynamic of me = FALSE
  123.   end if
  124.   
  125.   -- set CurrentVal =  compute_val() 
  126.   
  127. end
  128.  
  129. on prepareFrame me
  130.   -- limits motion of handle to extents of extentSprite
  131.   -- and locks the handle to the track of the extentSprite
  132.   
  133.   if tracking then
  134.     set handle = the spriteNum of me
  135.     set extent =  the extentSprite of me
  136.     
  137.     if the horizontal of me then    
  138.       set the newLocH of me = the mouseH
  139.       set the newLocV of me = the locV of sprite extent
  140.       if the newLocH of me < the left of sprite extent then
  141.         set the newLocH of me = the left of sprite extent
  142.       end if
  143.       if the newLocH of me > the right of sprite extent then
  144.         set the newLocH of me = the right of sprite extent
  145.       end if
  146.       
  147.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  148.       
  149.     else -- vertical slider
  150.       set the newLocH of me = the locH of sprite extent
  151.       set the newLocV of me = the mouseV
  152.       if the newLocV of me < the top of sprite extent then
  153.         set the newLocV of me = the top of sprite extent
  154.       end if
  155.       if the newLocV of me > the bottom of sprite extent then
  156.         set the newLocV of me = the bottom of sprite extent
  157.       end if   
  158.       
  159.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  160.       
  161.     end if  -- if vertical
  162.     
  163.     set the locH of sprite handle to the newLocH of me
  164.     set the locV of sprite handle to the newLocV of me
  165.     
  166.     if the dynamic of me then
  167.       send_the_val me, compute_val (me)
  168.     end if
  169.     
  170.   else   --  end if tracking, control slider position by movieTime
  171.     
  172.     set x = float(the movieTime of sprite VideoSprite)/ float(pDuration)
  173.     
  174.     
  175.     set handle = the spriteNum of me
  176.     set extent =  the extentSprite of me
  177.     
  178.     if the horizontal of me then
  179.       set ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  180.       set the newLocH of me = screenX
  181.       set the newLocV of me = the locV of sprite extent
  182.       if the newLocH of me < the left of sprite extent then
  183.         set the newLocH of me = the left of sprite extent
  184.       end if
  185.       if the newLocH of me > the right of sprite extent then
  186.         set the newLocH of me = the right of sprite extent
  187.       end if
  188.       
  189.       set the currentScreenVal of me = the newLocH of me - the minScreen of me
  190.       
  191.     else -- vertical slider
  192.       set ScreenY = the top of sprite extent + (x * (the bottom of sprite extent - the top of sprite extent))
  193.       set the newLocH of me = the locH of sprite extent
  194.       set the newLocV of me = ScreenY
  195.       if the newLocV of me < the top of sprite extent then
  196.         set the newLocV of me = the top of sprite extent
  197.       end if
  198.       if the newLocV of me > the bottom of sprite extent then
  199.         set the newLocV of me = the bottom of sprite extent
  200.       end if   
  201.       
  202.       set the currentScreenVal of me = the newLocV of me - the minScreen of me
  203.       
  204.     end if  -- if vertical
  205.     
  206.     set the locH of sprite handle to the newLocH of me
  207.     set the locV of sprite handle to the newLocV of me
  208.     
  209.   end if
  210.   
  211.   
  212. end
  213.  
  214. on mouseDown me 
  215.   set tracking = TRUE
  216.   set temp = the member of sprite the spritenum of me
  217.   set the member of sprite the spritenum of me = member the hiliteMember of me
  218.   set the hiliteMember of me = temp
  219. end
  220.  
  221. on mouseUp me
  222.   set tracking = FALSE
  223.   set temp = the member of sprite the spritenum of me
  224.   set the member of sprite the spritenum of me = member the hiliteMember of me
  225.   set the hiliteMember of me = temp
  226.   
  227.   if the sending of me then
  228.     set x = compute_val (me)
  229.     send_the_val me, x
  230.   end if
  231.   
  232. end
  233.  
  234. on mouseUpOutside me
  235.   set tracking = FALSE
  236.   set temp = the member of sprite the spritenum of me
  237.   set the member of sprite the spritenum of me = member the hiliteMember of me
  238.   set the hiliteMember of me = temp
  239.   
  240.   if the sending of me then
  241.     set x = compute_val (me)
  242.     send_the_val me, x
  243.   end if
  244.   
  245. end
  246.  
  247. on mouseEnter me
  248.   
  249. end
  250.  
  251. on mouseLeave me
  252.   
  253. end
  254.  
  255.  
  256.  
  257.